package router

import (
	"manage-server/controller"
	"manage-server/controller/im_controller/im_group_manage_controller"
	"manage-server/controller/im_controller/im_group_statistics_controller"
	"manage-server/controller/im_controller/im_invalid_group_controller"
	"manage-server/controller/im_controller/im_message_manage_controller"
	"manage-server/controller/im_controller/im_user_login_log_controller"
	"manage-server/controller/im_controller/im_user_login_statistics_controller"
	"manage-server/controller/im_controller/im_user_manage_controller"
	"manage-server/controller/im_controller/im_user_register_statistics_controller"
	"manage-server/controller/im_controller/im_wallet_controller/im_wallet_account_controller"
	"manage-server/controller/im_controller/im_wallet_controller/im_wallet_recharge_records_controller"
	"manage-server/controller/im_controller/im_wallet_controller/im_wallet_red_envelope_controller"
	"manage-server/controller/im_controller/im_wallet_controller/im_wallet_withdrawal_records_controller"
	"manage-server/controller/manage_controller/manage_admin_controller"
	"manage-server/controller/manage_controller/manage_login_log_controller"
	"manage-server/controller/manage_controller/manage_login_statistics_controller"
	"manage-server/controller/manage_controller/manage_param_config_controller"
	"manage-server/docs"
	"manage-server/middleware"

	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

// @title IvanApi Swagger 标题
// @version 1.0 版本
// @description IvanApi Service 描述
// @BasePath /api/v1  基础路径
// @query.collection.format multi
func InitRouter() *gin.Engine {
	r := gin.Default()
	// 跨域处理
	r.Use(middleware.CorsMiddleware())
	docs.SwaggerInfo.BasePath = "/api/v1"
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	v1 := r.Group("/api/v1")
	{
		v1.GET("/test", controller.Test{}.Test)
		// 后台管理
		manage := v1.Group("/manage")
		{
			// 后台用户管理
			admin := manage.Group("/admin")
			{
				admin.POST("/login", manage_admin_controller.AdminController{}.Login)                                                // 管理员登录
				admin.POST("/refresh_token", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.RefreshToken) // 管理员 token 刷新
				admin.GET("/info", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.Info)                   // 管理员信息
				admin.GET("/page", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.Page)                   // 管理员列表查询                                                // 管理员查询
				admin.GET("/create", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.Add)                  // 管理员新增
				admin.POST("/edit", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.Edit)                  //管理员编辑
				admin.POST("/delete", middleware.JWTAuthMiddleware(), manage_admin_controller.AdminController{}.Delete)              // 管理员删除
			}
			// 参数配置
			paramConfig := manage.Group("/param_config", middleware.JWTAuthMiddleware())
			{
				paramConfig.GET("/page", manage_param_config_controller.ParamConfigController{}.Page)      // 参数配置查询
				paramConfig.POST("/create", manage_param_config_controller.ParamConfigController{}.Create) // 参数配置新增
				paramConfig.POST("/edit", manage_param_config_controller.ParamConfigController{}.Edit)     // 参数配置编辑
				paramConfig.POST("/delete", manage_param_config_controller.ParamConfigController{}.Delete) // 参数配置删除
			}
			// 后台登录日志
			manageLoginLog := manage.Group("/login_log", middleware.JWTAuthMiddleware())
			{
				manageLoginLog.GET("/page", manage_login_log_controller.LoginLogController{}.Page)      //后台登录日志查询
				manageLoginLog.POST("/delete", manage_login_log_controller.LoginLogController{}.Delete) // 后台登录日志删除
			}
			// 后台管理统计
			manageLoginStatistics := manage.Group("/login_statistics", middleware.JWTAuthMiddleware())
			{
				manageLoginStatistics.GET("/page", manage_login_statistics_controller.LoginStatisticsController{}.Page) // 后台登录统计
			}
		}
		// 业务管理
		im := v1.Group("/im")
		{
			// 用户管理
			userManage := im.Group("/user_manage")
			{
				userManage.GET("/page", im_user_manage_controller.UserManageController{}.Page)                     // 用户查询
				userManage.POST("/create", im_user_manage_controller.UserManageController{}.Add)                   // 用户新增
				userManage.POST("/edit", im_user_manage_controller.UserManageController{}.Edit)                    // 用户编辑
				userManage.POST("/delete", im_user_manage_controller.UserManageController{}.Delete)                // 用户删除
				userManage.POST("/reset_password", im_user_manage_controller.UserManageController{}.ResetPassword) // 用户重置密码
				// 用户登录日志
				userLoginLog := userManage.Group("/login_log")
				{
					userLoginLog.GET("/page", im_user_login_log_controller.UserLoginLogController{}.Page)      // 用户登录日志查询
					userLoginLog.POST("/delete", im_user_login_log_controller.UserLoginLogController{}.Delete) // 用户登录日志删除
					userLoginLog.GET("/export", im_user_login_log_controller.UserLoginLogController{}.Export)  // 用户登录日志导出
				}
				// 用户登录统计
				userLoginStatistics := manage.Group("/user_login_statistics")
				{
					userLoginStatistics.GET("/page", im_user_login_statistics_controller.UserLoginStatistics{}.Page) // 用户登录统计查询
				}
				// 用户注册统计
				userRegisterStatistics := manage.Group("/register_statistics")
				{
					userRegisterStatistics.GET("/page", im_user_register_statistics_controller.UserRegisterStatisticsController{}.Page) // 用户注册统计查询
				}
			}
			// 消息管理
			messageManage := im.Group("/message_manage")
			{
				messageManage.GET("/single", im_message_manage_controller.MessageManageController{}.SinglePage) // 单聊记录查询
				messageManage.GET("/group", im_message_manage_controller.MessageManageController{}.GroupPage)   // 群聊记录查询
			}
			// 群组管理
			groupManage := im.Group("/group_manage")
			{
				groupManage.GET("/page", im_group_manage_controller.GroupManageController{}.Page)      // 群组查询
				groupManage.POST("/edit", im_group_manage_controller.GroupManageController{}.Edit)     // 群组编辑
				groupManage.POST("/delete", im_group_manage_controller.GroupManageController{}.Delete) // 群组删除
			}
			// 群组统计
			groupStatistics := im.Group("/group_statistics")
			{
				groupStatistics.GET("/page", im_group_statistics_controller.GroupStatisticsController{}.Page) // 群组统计查询
			}
			// 无效群组
			invalidGroup := im.Group("/invalid_group")
			{
				invalidGroup.GET("/page", im_invalid_group_controller.InvalidGroupController{}.Page) // 无效群组查询
			}
			// 钱包红包
			wallet := im.Group("/wallet")
			{
				// 用户账户
				account := wallet.Group("/account")
				{
					account.GET("/page", im_wallet_account_controller.WalletAccountController{}.Page)      // 用户账户查询
					account.POST("/edit", im_wallet_account_controller.WalletAccountController{}.Edit)     // 用户账户编辑
					account.POST("/delete", im_wallet_account_controller.WalletAccountController{}.Delete) // 用户账户删除
				}
				// 红包管理
				redEnvelope := wallet.Group("/red_envelope")
				{
					redEnvelope.GET("/page", im_wallet_red_envelope_controller.WalletRedEnvelopeController{}.Page)      // 红包管理查询
					redEnvelope.POST("/edit", im_wallet_red_envelope_controller.WalletRedEnvelopeController{}.Edit)     // 红包管理编辑
					redEnvelope.POST("/delete", im_wallet_red_envelope_controller.WalletRedEnvelopeController{}.Delete) // 红包管理删除
				}
				// 充值记录
				rechargeRecords := wallet.Group("/recharge_records")
				{
					rechargeRecords.GET("/page", im_wallet_recharge_records_controller.WalletRechargeRecordsController{}.Page)      // 充值记录查询
					rechargeRecords.POST("/delete", im_wallet_recharge_records_controller.WalletRechargeRecordsController{}.Delete) // 充值记录删除
				}
				// 提现记录
				withdrawalRecords := wallet.Group("/withdrawal_records")
				{
					withdrawalRecords.GET("/page", im_wallet_withdrawal_records_controller.WalletWithdrawalRecordsController{}.Page)      // 提现记录查询
					withdrawalRecords.POST("/delete", im_wallet_withdrawal_records_controller.WalletWithdrawalRecordsController{}.Delete) // 提现记录删除
				}
			}
		}
	}
	return r
}
